Skip to content

Wait for active interpreter resolution before reporting invalid interpreter - #26318

Open
MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
microsoft:mainfrom
wasim-builds:fix/issue-26317
Open

MOHAMMED WASIM KHAN (wasim-builds) wants to merge 1 commit into
microsoft:mainfrom
wasim-builds:fix/issue-26317

Conversation

@wasim-builds

Copy link
Copy Markdown

Fixes #26317.

Root Cause

InterpreterService.getActiveInterpreter races resolveActiveInterpreter against GET_ACTIVE_INTERPRETER_TIMEOUT_MS (100ms) so callers like language server startup are not blocked. On a cold start (no cached or persisted interpreter yet), if interpreter resolution takes longer than 100ms (e.g., when activated via another extension's API while the Python Environments extension is still resolving), getActiveInterpreter returns undefined while resolution is still in flight.

InvalidPythonInterpreterService._manualDiagnose called getActiveInterpreter(resource) directly and immediately surfaced InvalidPythonInterpreterDiagnostic ("An Invalid Python interpreter is selected...") when it received undefined.

Changes

  • Added waitForResolution?: boolean to GetActiveInterpreterOptions in src/client/interpreter/contracts.ts.
  • Updated InterpreterService.getActiveInterpreter in src/client/interpreter/interpreterService.ts to await resolution directly when options?.waitForResolution is true, preserving the 100ms timeout for all other callers.
  • Updated InvalidPythonInterpreterService._manualDiagnose and diagnoseDefaultShell in src/client/application/diagnostics/checks/pythonInterpreter.ts to pass { waitForResolution: true }.
  • Updated existing TypeMoq setups and added unit tests in pythonInterpreter.unit.test.ts and interpreterService.unit.test.ts.

Verification

  • npx tsc -p ./: 0 errors
  • npx mocha --require out/test/unittests.js --ui tdd out/test/application/diagnostics/checks/pythonInterpreter.unit.test.js out/test/interpreters/interpreterService.unit.test.js: 34 passing, 3 pending (Windows-only)
  • npx eslint on all 5 modified files: 0 errors

Copilot AI balanced review requested due to automatic review settings November 28, 2026 11:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new test fails on Windows because it expects one interpreter lookup, but _manualDiagnose() triggers two, so the expected call count must be platform-dependent.

1 open issue
What changed in this PR

This PR addresses #26317 by making interpreter diagnostics wait for resolution before reporting an invalid interpreter, while preserving the 100 ms timeout for other callers.

Changes:

  • Adds an opt-in waitForResolution option to active interpreter lookup.
  • Enables waiting in invalid-interpreter and default-shell diagnostics.
  • Updates mocks and adds regression tests for delayed resolution.
File Description
src/​test/​interpreters/​interpreterService.unit.test.ts Adds coverage for slow cold-start resolution.
src/​test/​application/​diagnostics/​checks/​pythonInterpreter.unit.test.ts Updates mocks and verifies diagnostics request resolution waiting.
src/​client/​interpreter/​interpreterService.ts Bypasses the timeout when waiting is requested.
src/​client/​interpreter/​contracts.ts Declares the optional waitForResolution flag.
src/​client/​application/​diagnostics/​checks/​pythonInterpreter.ts Waits for resolution before evaluating interpreter diagnostics.

Review effort: Balanced

),
)
.returns(() => Promise.resolve(({ path: 'interpreterpath' } as unknown) as PythonEnvironment))
.verifiable(typemoq.Times.once());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants